package DemoText;

/**
 * 不同路径二
 */
public class LeetCode63 {
    public int uniquePathsWithObstacles(int[][] nums) {
        int n = nums.length;
        int m = nums[0].length;
        int[][] dp = new int[n][m];
        for (int i = 0; i < n; i++)
            if (nums[i][0] != 1) dp[i][0] = 1;
            else break;
        for (int i = 0; i < m; i++)
            if(nums[0][i] != 1) dp[0][i] = 1;
            else break;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                if (nums[i][j] != 1) dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
        return dp[n - 1][m - 1];
    }
}
